package com.adcc.loadSheetForwarder.health;

import com.adcc.loadSheetForwarder.configuration.UmeTripProperties;
import com.adcc.loadSheetForwarder.service.UmeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

@Component("loadSheetHealth")
public class LoadSheetHealth extends AbstractHealthIndicator {
    @Autowired
    UmeTripProperties properties;

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        builder.withDetail("loadSheet", Status.UP.toString())
                .withDetail("umeInterface", UmeService.failCount.intValue() > properties.getMaxFailCount() ? Status.DOWN.toString() : Status.UP.toString())
                .up();
    }
}
